<template>
	<div class="box">
	<!--	<div class="user_list">
			<div class="user_title">用户列表</div>
			<el-tree :data="treeData" :props="Props" @node-click="handleNodeClick"></el-tree>
		</div>-->
		<div style="width: 100%;">
			<template>
				<el-table :data="tableData" style="width: 100%">
					<el-table-column prop="id" label="任务ID" width="180">
					</el-table-column>
					<el-table-column prop="synthesis_start_at" label="开始合成时间" width="180">
					</el-table-column>
					<el-table-column prop="synthesis_end_at" label="合成结束时间" width="180">
					</el-table-column>
					<el-table-column prop="completed_num" label="完成数">
					</el-table-column>
					<el-table-column prop="number" label="总数">
					</el-table-column>
					<el-table-column prop="creator" label="创建人">
					</el-table-column>
					<el-table-column label="操作">
						<template slot-scope="scope">
							<div class="check" @click="seeResult(scope.row)">查看合成结果</div>
						</template>
					</el-table-column>
				</el-table>
				<div class="fenye">
					<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
						:current-page="page"  :page-sizes="pageSizeLimit" :page-size="page_size"
						layout="total, sizes, prev, pager, next, jumper" :total="meiyeshu" >
					</el-pagination>
				</div>

			</template>
		</div>
	</div>
</template>

<script>
	import qs from 'qs'
    import {
        getTaskList,
    } from "../../../api";
	export default {
		//存放 数据
		data: function() {
			return {
				//分页
				page:1,
				page_size:100,
				pageCount:0,
				pageSizeLimit:[100, 200, 300, 400],
				user_id: 0,
				meiyeshu:0, //合计数量
				treeData: [],
				topid: 1,
				Props: {
					label: 'username',
					children: 'children',

				},
				tableData: []
			}
		},
		props: {
			tabindex: '',
			hecheng_id:0,
			// fileLists: {
			// 	type: Array,
			// 	default: function(){
			// 		// {
			// 		// 	id:56,
			// 		// 	name: 'food.jpeg',
			// 		// 	url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'
			// 		// }
			// 		return []
			// 	}
			// }
		},


		/*  生命周期函数  */
		//创建期间
		beforeCreate() {},
		created() {},
		beforeMount() {},
		mounted() {
			this.onload()

		},
		//运行期间
		beforeUpdate() {},
		updated() {},
		//销毁时期
		beforeDestroy() {},
		destroyed() {},
		//存放 方法
		methods: {
			handleNodeClick(data) {
				console.log(data);
				this.user_id = data.adminInfo.user_id;
				console.log(this.user_id);

				this.page = 1;
				this.onload();

			},
			handleSizeChange(val){
				// console.log(val)
				this.page = 1;
				this.page_size = val;
				this.onload();
			},
			handleCurrentChange(val){},

            async onload() {
                let res = await getTaskList({
                  page:this.page,
                  page_size:this.page_size,
                }).catch((e) => e);
                if (res.code == 200 || res.msg == "success") {
                    this.tableData= res.data.list;
                    this.meiyeshu=res.data.total
                }
				/*this.http.post(`/admin/admin-info/zuhu-list`, {
						'form[page]': 1,
						'form[page_size]': 10000,
						'form[keyword]': '',
					})
					.then(res => {
						if (res) {
							this.topid = res.data.data.topid;
							this.treeData.push({
								id: 1,
								username: "admim",
								children: [],
								adminInfo: {
									topid: 0
								}
							})
							this.geshihua(res.data.data.list);
							console.log(this.treeData)
						}
					})

				this.getRenwuList();*/

			},

			getRenwuList() {
				this.http.post(this.api.apiUrlShipin+`/admin/hecheng/list`, {
						'form[page]': this.page,
						'form[page_size]': this.page_size,
						'form[user_id]': this.user_id,
					})
					.then(res => {
						if (res) {
							this.tableData = res.data.data.list;

							this.meiyeshu = res.data.data.pagination.total_count;
							this.pageCount = res.data.data.pagination.page_count;

						}
					})
			},

			//查看合成结果
			seeResult(row){
				this.hecheng_id = row.id
				// console.log(this.id)
				// this.$router.push({
				// 	path: '/user/plan_list?id=' + this.id + '&&' + 'ids=' + ids
				// });

				console.log("hecheng-id=", row.id)

				this.$emit("update:hecheng_id", row.id)
				this.$emit("update:tabindex", 3)

			},

			geshihua(resitem) {
				let that = this;
				let tmpArr = resitem.filter(item => {
					if (item.adminInfo.topid == that.topid) {
						this.treeData[0].children.push(item);
					} else {
						return item;
					}
				});
				const test = (children, item, i) => {
					children.forEach(routesItem => {
						if (routesItem.adminInfo.id == item.adminInfo.topid) {
							if ('children' in routesItem) {
								routesItem.children.push(item);
							} else {
								routesItem.children = [];
								routesItem.children.push(item);
							}
							tmpArr.splice(i, 1); // 将使后面的元素依次前移，数组长度减1
							i--; // 如果不减，将漏掉一个元素
							return true;
						} else {
							if ('children' in routesItem && routesItem.children) {
								test(routesItem.children, item);
							}
						}

					});

				}
				while (tmpArr.length) {
					for (let i = 0; i < tmpArr.length; i++) {
						let tmpArrItem = tmpArr[i];
						this.treeData.forEach(treeDataItem => {
							if (tmpArrItem.adminInfo.topid == treeDataItem.adminInfo.id) {
								if ('children' in treeDataItem) {
									treeDataItem.children.push(tmpArrItem)
								} else {
									treeDataItem.children = []
									treeDataItem.children.push(tmpArrItem)
								}
								tmpArr.splice(i, 1); // 将使后面的元素依次前移，数组长度减1
								i--; // 如果不减，将漏掉一个元素
							} else {

								if ('children' in treeDataItem) {
									let a = test(treeDataItem.children, tmpArrItem, i);

									if (a == true) {
										i--; // 如果不减，将漏掉一个元素
									}
								};
							}
						});

					}
				}



			},
		},
		//存放 过滤器
		filters: {},
		//自定义 私有指令
		directives: {},
		// 注意： 组件中的 所有 props 中的数据，都是通过 父组件传递给子组件的
		// props 中的数据，都是只读的，无法重新赋值
		// props: [], // 把父组件传递过来的 parentmsg 属性，先在 props 数组中，定义一下，这样，才能使用这个数据
	}
</script>

<style scoped>
	.user_list {
		flex: 0 0 250px;
		margin-right: 24px;
		padding: 20px;
		min-height: 100%;
		background: #fff;
	}

	.user_title {
		margin-bottom: 10px;
		font-size: 16px;
		font-weight: 600;
	}

	.box {
		display: flex;
	}
	.fenye{
		margin: 20px 0;
		text-align: right;
	}
	.check{
		color: #409EFF;
	}
</style>
